package org.geektimes.configuration.microprofile.config.source;

import javax.servlet.ServletContext;
import java.util.Enumeration;
import java.util.Map;

/**
 * @author :   chuan
 * @date :   2021/03/23
 */
public class ServletContextConfigSource extends MapBasedConfigSource {

    public ServletContextConfigSource(ServletContext servletContext) {
        super("ServletContextConfigSource", 500, servletContext);
    }

    @Override
    protected void prepareConfigData(Map configData) throws Throwable {
        Enumeration<String> initParameterNames = this.servletContext.getInitParameterNames();
        while (initParameterNames.hasMoreElements()) {
            String element = initParameterNames.nextElement();
            configData.put(element, servletContext.getInitParameter(element));
        }
    }
}
